var verify_item_within_yellow_label_conflict = JSON.parse('{"CODE":0, "ACTION":"","LEVEL":"T1", "MSG":"","DATA":"","SCRIPTNAME":"verify_item_within_yellow_label_conflict"}');

var yellow_label_conflict_idList = []
var yellow_label_conflict_idSet = []

if (!isNull(retail_tax) && !isNull(yellowLabelList)) {
    var retailStartDateForYellowLabel = getNewBeginDate(new Date(retail_start_date));
    var retailEndDateForYellowLabel = '';
    if (isNull(retail_end_date)) {
        retailEndDateForYellowLabel = getNewEndDate(new Date('2049-12-31'));
    } else {
        retailEndDateForYellowLabel = getNewEndDate(new Date(retail_end_date));
    }
    yellowLabelList.forEach(function (yellowLabel) {
        if (yellowLabel.itemNbr == item_nbr && !isNull(yellowLabel.storeNbr)) {
            if (trait_nbr == 'ALL') {
                var yellow_label_conflict_overlaps = overlaps(retailStartDateForYellowLabel, retailEndDateForYellowLabel, yellowLabel.originalDate, yellowLabel.expireDate)
                if (yellow_label_conflict_overlaps) {
                    yellow_label_conflict_idList.push(yellowLabel.itemId)
                }
            } else if (!isNull(trait_nbr)) {
                if (trait_store.containsKey(trait_nbr)) {
                    var clubList = trait_store.get(trait_nbr)
                    if (!isNull(clubList)) {
                        var yellow_label_conflict_flag = false
                        clubList.forEach(function (club) {
                            if (club == yellowLabel.storeNbr && !yellow_label_conflict_flag) {
                                var yellow_label_conflict_overlaps = overlaps(retailStartDateForYellowLabel, retailEndDateForYellowLabel, yellowLabel.originalDate, yellowLabel.expireDate)
                                if (yellow_label_conflict_overlaps) {
                                    yellow_label_conflict_idList.push(yellowLabel.itemId)
                                    yellow_label_conflict_flag = true;
                                }
                            }
                        })
                    }
                }
            } else if (!isNull(store_id) && store_type == 1) {
                if (store_id == yellowLabel.storeNbr) {
                    var yellow_label_conflict_overlaps = overlaps(retailStartDateForYellowLabel, retailEndDateForYellowLabel, yellowLabel.originalDate, yellowLabel.expireDate)
                    if (yellow_label_conflict_overlaps) {
                        yellow_label_conflict_idList.push(yellowLabel.itemId)
                        yellow_label_conflict_flag = true;
                    }
                }
            }
        }
    })
}

if (yellow_label_conflict_idList.length > 0) {
    yellow_label_conflict_idList.forEach(function (yellow_label_conflict_id) {
        if (yellow_label_conflict_idSet.indexOf(yellow_label_conflict_id) == -1) {
            yellow_label_conflict_idSet.push(yellow_label_conflict_id);
        }
    })
    verify_item_within_yellow_label_conflict.CODE = 2;
    verify_item_within_yellow_label_conflict.ACTION = 'error';
    verify_item_within_yellow_label_conflict.MSG = '变价和黄价签冲突不可变价，黄价签单号[' + yellow_label_conflict_idSet.join(',') + ']';
}

JSON.stringify(verify_item_within_yellow_label_conflict);
